﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EvectionEdit.aspx.cs" Inherits="Web.EvectionEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>出差申请 编辑</title>
    <base target="_self" />
    <meta content="ie=7" http-equiv="x-ua-compatible">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <link href="Styles/Style01.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
    <script src="Scripts/easy_validator.pack.js" type="text/javascript"></script>
    <script>
        //iframe高度自适应
        function IFrameReSize(iframename) {
            var pTar = document.getElementById(iframename);
            if (pTar) {  //ff
                if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
                    pTar.height = pTar.contentDocument.body.offsetHeight;
                } //ie
                else if (pTar.Document && pTar.Document.body.scrollHeight) {
                    pTar.height = pTar.Document.body.scrollHeight;
                }
            }
        }
        //iframe宽度自适应
        function IFrameReSizeWidth(iframename) {
            var pTar = document.getElementById(iframename);
            if (pTar) {  //ff
                if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {
                    pTar.width = pTar.contentDocument.body.offsetWidth;
                }  //ie
                else if (pTar.Document && pTar.Document.body.scrollWidth) {
                    pTar.width = pTar.Document.body.scrollWidth;
                }
            }
        }

        //取get参数
        function getArg() {
            var url = unescape(window.location.href);
            var allArgs = url.split("?")[1];
            if (allArgs != null) {
                var args = allArgs.split("&");
                for (var i = 0; i < args.length; i++) {
                    var arg = args[i].split("=");
                    eval('this.' + arg[0] + '="' + arg[1] + '";');
                }
            }
        }
        var urlArg = new getArg();
        var formNo = urlArg.formNo;

        $(function () {
            $("[reg]").parents("td").prev().append("<font color='#ff0000'>*</font>");
            $("#btnSave").click(function () {
                return formValid();
            });
            $("#btnSubmit").click(function () {
                var trs = $("#tbDetail tbody").find("tr");
                if (trs.length == 0) { alert('请增加 旅程明细~'); return false; }
                return formValid();
            });
        });
        function formValid() {
            var isSubmit = true;
            $("form").find("[reg],[url]:not([reg])").each(function () {
                if (!validate($(this), this.tagName)) {
                    isSubmit = false;
                }
            });
            if (!isSubmit) {
                alert("请确认'红字或红框'处的输入正确!");
                return false;
            }
            return true;
        }
        function scheduleEdit(id) {
            var url = 'EvecScheduleEdit.aspx?formNo='+formNo;
            if (id != undefined) {
                url = 'EvecScheduleEdit.aspx?id=' + id;
            }
            var retVal = window.showModalDialog(url, window, 'dialogWidth=550px;dialogHeight=550px;status=no;help=no;resizable=yes;');
            if (retVal != undefined && retVal.indexOf('Succeed') >= 0) {
                window.name = "__self";
                window.open(window.location.href, "__self");
            }
        }
        function scheduleDel(id) {
            if (confirm('您确定删除该行记录吗?')) {
                $.ajax({ type: 'post', url: "/Evection.mvc/DelSchedules", data: { id: id },
                    success: function (data, textStatus) {
                        if (data == "Succeed") {
                            window.name = "__self";
                            window.open(window.location.href, "__self");
                        }
                    }
                });
            }
        }

        function voyageEdit(id) {
            var url = 'EvecVoyageEdit.aspx?formNo=' + formNo;
            if (id != undefined) {
                url = 'EvecVoyageEdit.aspx?id=' + id;
            }
            var retVal = window.showModalDialog(url, window, 'dialogWidth=550px;dialogHeight=550px;status=no;help=no;resizable=yes;');
            if (retVal != undefined && retVal.indexOf('Succeed') >= 0) {
                window.name = "__self";
                window.open(window.location.href, "__self");
            }
        }
        function voyageDel(id) {
            if (confirm('您确定删除该行记录吗?')) {
                $.ajax({ type: 'post', url: "/Evection.mvc/DelVoyages", data: { id: id },
                    success: function (data, textStatus) {
                        if (data == "Succeed") {
                            window.name = "__self";
                            window.open(window.location.href, "__self");
                        }
                    }
                });
            }
        }

        function flighterEdit(id) {
            var url = 'EvecFlighterEdit.aspx?formNo=' + formNo;
            if (id != undefined) {
                url = 'EvecFlighterEdit.aspx?id=' + id;
            }
            var retVal = window.showModalDialog(url, window, 'dialogWidth=550px;dialogHeight=550px;status=no;help=no;resizable=yes;');
            if (retVal != undefined && retVal.indexOf('Succeed') >= 0) {
                window.name = "__self";
                window.open(window.location.href, "__self");
            }
        }
        function flighterDel(id) {
            if (confirm('您确定删除该行记录吗?')) {
                $.ajax({ type: 'post', url: "/Evection.mvc/DelFlighters", data: { id: id },
                    success: function (data, textStatus) {
                        if (data == "Succeed") {
                            window.name = "__self";
                            window.open(window.location.href, "__self");
                        }
                    }
                });
            }
        }
    </script>
    <link href="Styles/validate.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="Form1" runat=server><input type=hidden runat=server id=FormNo />
<table class="s1">
<tr><td>表单编号</td><td><%=reqEvectionMain.FormNo%></td><td>申请时间</td><td><%=reqEvectionMain.ReqDate.ToString("yyyy-MM-dd HH:mm:ss")%></td></tr>
<tr><td>申请人</td><td><%=empName%></td><td>预计费用</td><td><input id="PreCost" runat="server" title="请输入非负整数" reg="^\d+(\.\d{1,2})?$"></td></tr>
<tr><td>出差人</td><td colspan=3><input id="TriperIds" runat="server" title="多个出差人用','号隔开" reg="."></td></tr>
<tr><td>申请备注</td><td colspan=3><input id="Cause" runat="server"></td></tr>
</table>
<asp:Repeater ID="rptList" EnableViewState="False" Runat="server">
	<HeaderTemplate>
		<table id="tbDetail" class="s1 list">
			<caption>旅程明细<input type=button onclick="javascript:scheduleEdit();" value="添加旅程"/></caption>
			<thead>
				<TR>
					<th width="15%">预计开始日期</th>
					<th width="15%">预计结束日期</th>
					<th width="10%">交通工具</th>
					<th width="10%">出发地</th>
					<th width="10%">到达地</th>
					<th width="20%">备注</th>
					<th class="tdOrder">操作</th>
				</TR>
			</thead><tbody>
	</HeaderTemplate>
	<ItemTemplate>
		<tr class="<%# Container.ItemIndex%2==0?"bg":""%>">
			<td><%# DataBinder.Eval(Container.DataItem, "PreStartTime","{0:d}")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "PreEndTime", "{0:d}")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "TrafficTool")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "LeavePoint")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "ArrivePoint")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "Cause")%></td>
			<td>
                <a href="#" onclick="scheduleEdit(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[编辑]</a>
                <a href="#" onclick="scheduleDel(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[删除]</a>
			</td>
		</tr>
	</ItemTemplate>
	<FooterTemplate>
		</tbody> </table>
	</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptVoyage" EnableViewState="False" Runat="server">
	<HeaderTemplate>
		<table class="s1 list">
			<caption>航程明细<input type=button onclick="javascript:voyageEdit();" value="添加航程"/></caption>
			<thead>
				<TR>
					<th width="15%">出发日期时间段</th>
					<th width="15%">到达日期时间段</th>
					<th width="15%">出发地</th>
					<th width="15%">到达地</th>
					<th width="20%">取票时间段</th>
					<th class="tdOrder">操作</th>
				</TR>
			</thead><tbody>
	</HeaderTemplate>
	<ItemTemplate>
		<tr class="<%# Container.ItemIndex%2==0?"bg":""%>">
			<td><%# DataBinder.Eval(Container.DataItem, "PreLeaveTimeSpan")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "PreArriveTimeSpan")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "LeavePoint")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "ArrivePoint")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "PrePickTimeSpan")%></td>
			<td>
                <a href="#" onclick="voyageEdit(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[编辑]</a>
                <a href="#" onclick="voyageDel(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[删除]</a>
			</td>
		</tr>
	</ItemTemplate>
	<FooterTemplate>
		</tbody> </table>
	</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptFlighter" EnableViewState="False" Runat="server">
	<HeaderTemplate>
		<table class="s1 list">
			<caption>乘机人明细<input type=button onclick="javascript:flighterEdit();" value="添加乘机人"/></caption>
			<thead>
				<TR>
					<th width="20%">乘机人</th>
					<th width="20%">身份证号</th>
					<th width="20%">手机号</th>
					<th class="tdOrder">操作</th>
				</TR>
			</thead><tbody>
	</HeaderTemplate>
	<ItemTemplate>
		<tr class="<%# Container.ItemIndex%2==0?"bg":""%>">
			<td><%# DataBinder.Eval(Container.DataItem, "FlighterName")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "FlighterId")%></td>
			<td><%# DataBinder.Eval(Container.DataItem, "FlighterCell")%></td>
			<td>
                <a href="#" onclick="flighterEdit(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[编辑]</a>
                <a href="#" onclick="flighterDel(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[删除]</a>
			</td>
		</tr>
	</ItemTemplate>
	<FooterTemplate>
		</tbody> </table>
	</FooterTemplate>
</asp:Repeater>
<div style="text-align:right;margin-right:24px;margin-top:6px;">
    <asp:button runat="server" text="保存" class="btn" id="btnSave" onclick="btnSave_Click"/>
    <asp:button runat="server" text="提交" class="btn" id="btnSubmit" onclick="btnSubmit_Click"/>
    <input type=button value="关闭" class="btn" onclick="window.close();" />
</div>
</form>
</body>
</html>